package com.yupi.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.project.common.BaseResponse;
import com.yupi.project.common.ErrorCode;
import com.yupi.project.common.ResultUtils;
import com.yupi.project.exception.BusinessException;
import com.yupi.project.mapper.FarmerMapper;
import com.yupi.project.model.dto.famer.GoodsDto;
import com.yupi.project.model.entity.Farmer;
import com.yupi.project.service.FarmerService;

import com.yupi.project.utils.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 86189
 * @description 针对表【tb_farmer】的数据库操作Service实现
 * @createDate 2023-01-12 13:21:26
 */
@Service
public class FarmerServiceImpl extends ServiceImpl<FarmerMapper, Farmer>
        implements FarmerService {
    @Override
    public BaseResponse addFoods(GoodsDto goodsDto, MultipartFile image) {
        if (goodsDto == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        if (image == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        LambdaQueryWrapper<Farmer> eq = new LambdaQueryWrapper<Farmer>().eq(Farmer::getArea, "12");
        Farmer farmer = new Farmer();
        BeanUtils.copyProperties(goodsDto, farmer);
        String imageName = FileUtils.upload(image);
        farmer.setImage(imageName);
        boolean isSuccess = this.save(farmer);
        return ResultUtils.success(isSuccess);
    }
}




